package com.ztr.designpatterns.singleton;

public class Client {
    public static void main(String args[]){
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        //判断两个对象是否相同
        if(s1 == s2){
            System.out.println("两个对象是相同实例");
        }
        else{
            System.out.println("两个对象是不同实例");
        }

        //创建四个Bowl碗对象
        Bowl Bowl1,Bowl2,Bowl3,Bowl4;
        Bowl1 = Bowl.getBowl();
        Bowl2 = Bowl.getBowl();
        Bowl3 = Bowl.getBowl();
        Bowl4 = Bowl.getBowl();

        //判断Bowl碗是否想同
        if(Bowl1== Bowl2&Bowl2== Bowl3&Bowl3 == Bowl4){
            System.out.println("碗具有唯一性");
        }

        //增加吃饭的人
        Bowl1.addPerson("Person1");
        Bowl2.addPerson("Person2");
        Bowl3.addPerson("Person3");
        Bowl4.addPerson("Person4");

        //模拟客户端请求的分发，如果输出结果为同一个person,可以将i适当放大
        //例如改为i<100
        for(int i = 0;i<10;i++){
            String person = Bowl1.getPerson();
            System.out.println("分发请求到吃饭的人："+person);
        }


    }
}
